﻿/**
 * Copyright (c) 2008 michiyasu wada
 * http://www.seyself.com/
 * 
 * Distributed under The MIT License.
 * [http://www.opensource.org/licenses/mit-license.php]
 */

package demo.objects.items 
{
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.text.TextFormat;
import jp.progression.casts.CastButton;
import jp.progression.casts.CastSprite;
import jp.progression.casts.CastTextField;
import flash.display.MovieClip;
import flash.text.TextFieldType;

public class SearchBox  extends CastSprite
{
    public var input:CastTextField;
    
    //--------------------------------------------------------------------------
    //  Constructor
    //--------------------------------------------------------------------------
    public function SearchBox() 
    {
        addEventListener( Event.ADDED_TO_STAGE , addedHandler );
    }
    
    //--------------------------------------------------------------------------
    //  Event Handler Methods
    //--------------------------------------------------------------------------
    private function addedHandler( event:Event ):void
    {
        input = new CastTextField();
        this.addChild( input );
        input.x = 20;
        input.y = 3;
        input.width = 140;
        input.height = 22;
        input.type = TextFieldType.INPUT;
        input.text = "Flash";
        
        var fmt:TextFormat = new TextFormat();
        fmt.font = "_等幅";
        fmt.size = 12;
        fmt.color = 0x666666;
        
        input.defaultTextFormat = fmt;
        input.setTextFormat( fmt );
        
        this.addEventListener( KeyboardEvent.KEY_DOWN, keyDownHandler );
        
    }
    
    private function keyDownHandler( event:KeyboardEvent ):void
    {
        if ( event.charCode == 13 ) {
            dispatchEvent( new Event( "enter" ) );
        }
    }
}

}